Skip to content

fix(mesh): use memmove for overlapping path shift#1904

Open
robekl wants to merge 1 commit intomeshcore-dev:devfrom
robekl:fix/remove-self-path-memmove
Open

fix(mesh): use memmove for overlapping path shift#1904
robekl wants to merge 1 commit intomeshcore-dev:devfrom
robekl:fix/remove-self-path-memmove

Conversation

@robekl
Copy link

@robekl robekl commented Mar 3, 2026

This PR fixes undefined behavior in direct-route path rewriting by replacing an overlapping memcpy with memmove.

Problem / Impact

removeSelfFromPath() shifts path entries left in-place after decrementing the hop count.
Source and destination ranges overlap by design (dest = path + k, src = path + k + sz).

Using memcpy on overlapping ranges is undefined behavior in C/C++.

On embedded builds, UB here can lead to:

  • corrupted route paths,
  • intermittent forwarding failures,
  • architecture/libc/optimization-dependent behavior that is difficult to reproduce and debug.

Because this function is in the packet forwarding path, even rare corruption can have high network reliability impact.

Why This Fix Is Correct

memmove is defined for overlapping memory regions and preserves the intended in-place shift semantics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant